package com.qifan.alb2b.dao;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.stereotype.Repository;

import com.cqcis.base.orm.jdbc.JdbcUtil;
import com.qifan.alb2b.domain.RouteInfoDomain;
import com.qifan.alb2b.domain.TravelInfoDomain;
import com.qifan.alb2b.domain.TravelItemInfoDomain;
import com.qifan.alb2b.util.Page;

@Repository
public class TravelInfoDao extends BaseDao{
	
	public void add(TravelInfoDomain travelInfo){
		super.addObj(travelInfo);
	}
	
	/**
	 * 批量添加
	 * @param list
	 */
	public void add(List<TravelInfoDomain> list){
		final List<TravelInfoDomain> tempList=list;
		String sql="insert into TRAVELINFO(TRAVELID,ORDERID,WHICHDAY,DEPART,ARRIVAL,CITYID,CITYCN,TOTALPRICE,STDPRICE,ADDPRICE,REMARK) values(?,?,?,?,?,?,?,?,?,?,?)";
		this.getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() {
			
			public void setValues(PreparedStatement ps, int i) throws SQLException {
				ps.setString(1, tempList.get(i).getTravelId());
				ps.setString(2,tempList.get(i).getOrderId());
				ps.setInt(3, tempList.get(i).getWhichDay());
				ps.setString(4, tempList.get(i).getDepart());
				ps.setString(5, tempList.get(i).getArrival());
				ps.setString(6, tempList.get(i).getCityId());
				ps.setString(7, tempList.get(i).getCityCn());
				ps.setDouble(8, tempList.get(i).getTotalPrice());
				ps.setDouble(9,tempList.get(i).getStdPrice());
				ps.setDouble(10, tempList.get(i).getAddPrice());
				ps.setString(11, tempList.get(i).getRemark());
			}
			
			public int getBatchSize() {				
				return tempList.size();
			}
		});
	}
	
	/**
	 * 根据orderId查询线路详情
	 * @param routeId
	 * @return
	 */
	public List<TravelInfoDomain> query(String orderId){
		String sql="select * from travelInfo where orderId=? order by whichDay asc";
		return JdbcUtil.queryForList(this, TravelInfoDomain.class, sql, orderId);
	}

}
